/***********************************************************************************
File        : compile_small_data.do 
Authors     : Ariel Dora Stern & Nick Menzies
Created     : 24 Mar 2010
Modified    : 26 Mar 2010
Description : Compile DHS Data for Gov 2001 Paper
***********************************************************************************/
clear
set more off
set linesize 200
set mem 500m
cd "C:\Users\Nick\Documents\Harvard\Courses\Gov 2001\Replication Paper\Data files\Country files"
local mergers `"country hv001 hv002 hv003"'  
		
***EXPAND HOUSEHOLD LEVEL VARIABLES for each small data set ***

**BF
use BF_SMALL.dta
by hv001 hv002, sort: egen efloor2 = max(efloor)
	drop efloor
	rename efloor2 efloor
by hv001 hv002, sort: egen catholic2 = max(catholic)
	drop catholic
	rename catholic2 catholic
by hv001 hv002, sort: egen muslim2 = max(muslim)
	drop muslim
	rename muslim2 muslim
by hv001 hv002, sort: egen prot2 = max(protestant)
	drop protestant
	rename prot2 protestant
by hv001 hv002, sort: egen oth_r2 = max(oth_relig)
	drop oth_relig
	rename oth_r2 oth_relig
by hv001 hv002, sort: egen toilet2 = max(toilet)
	drop toilet
	rename toilet2 toilet
by hv001 hv002, sort: egen electr2 = max(electr)
	drop electr
	rename electr2 electr
by hv001 hv002, sort: egen radio2 = max(radio)
	drop radio
	rename radio2 radio
by hv001 hv002, sort: egen tv2 = max(tv)
	drop tv
	rename tv2 tv
by hv001 hv002, sort: egen refrig2 = max(refrig)
	drop refrig
	rename refrig2 refrig
by hv001 hv002, sort: egen bike2 = max(bike)
	drop bike
	rename bike2 bike
by hv001 hv002, sort: egen motorc2 = max(motorc)
	drop motorc
	rename motorc2 motorc
by hv001 hv002, sort: egen car2 = max(car)
	drop car
	rename car2 car
by hv001 hv002, sort: egen urban2 = max(urban)
	drop urban
	rename urban2 urban

sort `mergers'
save, replace
clear

**CM
use CM_SMALL.dta
by hv001 hv002, sort: egen efloor2 = max(efloor)
	drop efloor
	rename efloor2 efloor
by hv001 hv002, sort: egen catholic2 = max(catholic)
	drop catholic
	rename catholic2 catholic
by hv001 hv002, sort: egen muslim2 = max(muslim)
	drop muslim
	rename muslim2 muslim
by hv001 hv002, sort: egen prot2 = max(protestant)
	drop protestant
	rename prot2 protestant
by hv001 hv002, sort: egen oth_r2 = max(oth_relig)
	drop oth_relig
	rename oth_r2 oth_relig

by hv001 hv002, sort: egen toilet2 = max(toilet)
	drop toilet
	rename toilet2 toilet
by hv001 hv002, sort: egen electr2 = max(electr)
	drop electr
	rename electr2 electr
by hv001 hv002, sort: egen radio2 = max(radio)
	drop radio
	rename radio2 radio
by hv001 hv002, sort: egen tv2 = max(tv)
	drop tv
	rename tv2 tv
by hv001 hv002, sort: egen refrig2 = max(refrig)
	drop refrig
	rename refrig2 refrig
by hv001 hv002, sort: egen bike2 = max(bike)
	drop bike
	rename bike2 bike
by hv001 hv002, sort: egen motorc2 = max(motorc)
	drop motorc
	rename motorc2 motorc
by hv001 hv002, sort: egen car2 = max(car)
	drop car
	rename car2 car
by hv001 hv002, sort: egen urban2 = max(urban)
	drop urban
	rename urban2 urban

sort `mergers'
save, replace
clear

**GH
use GH_SMALL.dta
by hv001 hv002, sort: egen efloor2 = max(efloor)
	drop efloor
	rename efloor2 efloor
by hv001 hv002, sort: egen catholic2 = max(catholic)
	drop catholic
	rename catholic2 catholic
by hv001 hv002, sort: egen muslim2 = max(muslim)
	drop muslim
	rename muslim2 muslim
by hv001 hv002, sort: egen prot2 = max(protestant)
	drop protestant
	rename prot2 protestant
by hv001 hv002, sort: egen oth_r2 = max(oth_relig)
	drop oth_relig
	rename oth_r2 oth_relig
by hv001 hv002, sort: egen toilet2 = max(toilet)
	drop toilet
	rename toilet2 toilet
by hv001 hv002, sort: egen electr2 = max(electr)
	drop electr
	rename electr2 electr
by hv001 hv002, sort: egen radio2 = max(radio)
	drop radio
	rename radio2 radio
by hv001 hv002, sort: egen tv2 = max(tv)
	drop tv
	rename tv2 tv
by hv001 hv002, sort: egen refrig2 = max(refrig)
	drop refrig
	rename refrig2 refrig
by hv001 hv002, sort: egen bike2 = max(bike)
	drop bike
	rename bike2 bike
by hv001 hv002, sort: egen motorc2 = max(motorc)
	drop motorc
	rename motorc2 motorc
by hv001 hv002, sort: egen car2 = max(car)
	drop car
	rename car2 car
by hv001 hv002, sort: egen urban2 = max(urban)
	drop urban
	rename urban2 urban

sort `mergers'
save, replace
clear

**KE
use KE_SMALL.dta
by hv001 hv002, sort: egen efloor2 = max(efloor)
	drop efloor
	rename efloor2 efloor
by hv001 hv002, sort: egen catholic2 = max(catholic)
	drop catholic
	rename catholic2 catholic
by hv001 hv002, sort: egen muslim2 = max(muslim)
	drop muslim
	rename muslim2 muslim
by hv001 hv002, sort: egen prot2 = max(protestant)
	drop protestant
	rename prot2 protestant
by hv001 hv002, sort: egen oth_r2 = max(oth_relig)
	drop oth_relig
	rename oth_r2 oth_relig
by hv001 hv002, sort: egen toilet2 = max(toilet)
	drop toilet
	rename toilet2 toilet
by hv001 hv002, sort: egen electr2 = max(electr)
	drop electr
	rename electr2 electr
by hv001 hv002, sort: egen radio2 = max(radio)
	drop radio
	rename radio2 radio
by hv001 hv002, sort: egen tv2 = max(tv)
	drop tv
	rename tv2 tv
by hv001 hv002, sort: egen refrig2 = max(refrig)
	drop refrig
	rename refrig2 refrig
by hv001 hv002, sort: egen bike2 = max(bike)
	drop bike
	rename bike2 bike
by hv001 hv002, sort: egen motorc2 = max(motorc)
	drop motorc
	rename motorc2 motorc
by hv001 hv002, sort: egen car2 = max(car)
	drop car
	rename car2 car
by hv001 hv002, sort: egen urban2 = max(urban)
	drop urban
	rename urban2 urban

sort `mergers'
save, replace
clear

**TZ
use TZ_SMALL.dta
by hv001 hv002, sort: egen efloor2 = max(efloor)
	drop efloor
	rename efloor2 efloor
by hv001 hv002, sort: egen catholic2 = max(catholic)
	drop catholic
	rename catholic2 catholic
by hv001 hv002, sort: egen muslim2 = max(muslim)
	drop muslim
	rename muslim2 muslim
by hv001 hv002, sort: egen prot2 = max(protestant)
	drop protestant
	rename prot2 protestant
by hv001 hv002, sort: egen oth_r2 = max(oth_relig)
	drop oth_relig
	rename oth_r2 oth_relig
by hv001 hv002, sort: egen toilet2 = max(toilet)
	drop toilet
	rename toilet2 toilet
by hv001 hv002, sort: egen electr2 = max(electr)
	drop electr
	rename electr2 electr
by hv001 hv002, sort: egen radio2 = max(radio)
	drop radio
	rename radio2 radio
by hv001 hv002, sort: egen tv2 = max(tv)
	drop tv
	rename tv2 tv
by hv001 hv002, sort: egen refrig2 = max(refrig)
	drop refrig
	rename refrig2 refrig
by hv001 hv002, sort: egen bike2 = max(bike)
	drop bike
	rename bike2 bike
by hv001 hv002, sort: egen motorc2 = max(motorc)
	drop motorc
	rename motorc2 motorc
by hv001 hv002, sort: egen car2 = max(car)
	drop car
	rename car2 car
by hv001 hv002, sort: egen urban2 = max(urban)
	drop urban
	rename urban2 urban

sort `mergers'
save, replace
clear

**---
use BF_SMALL.dta
merge `mergers' using CM_SMALL.dta
sort `mergers'
drop _m

merge `mergers' using GH_SMALL.dta
sort `mergers'
drop _m

merge `mergers' using KE_SMALL.dta
sort `mergers'
drop _m

merge `mergers' using TZ_SMALL.dta
sort `mergers'
drop _m

***** Need to create zero values for dummy variables

** Burkina Faso

replace eth11=0 if eth11==.
replace eth12=0 if eth12==.
replace eth13=0 if eth13==.
replace eth14=0 if eth14==.
replace eth15=0 if eth15==.
replace eth16=0 if eth16==.
replace eth17=0 if eth17==.
replace eth18=0 if eth18==.
replace eth19=0 if eth19==.
replace eth110=0 if eth110==.
replace eth111=0 if eth111==.

replace reg11=0 if reg11==.
replace reg12=0 if reg12==. 
replace reg13=0 if reg13==.
replace reg14=0 if reg14==.
replace reg15=0 if reg15==.
replace reg16=0 if reg16==.
replace reg17=0 if reg17==.
replace reg18=0 if reg18==.
replace reg19=0 if reg19==.
replace reg110=0 if reg110==.
replace reg111=0 if reg111==.
replace reg112=0 if reg112==.
replace reg113=0 if reg113==.
replace reg114=0 if reg114==.
 	
replace age11=0 if age11==.
replace age12=0 if age12==.
replace age13=0 if age13==.
replace age14=0 if age14==.
replace age15=0 if age15==.
replace age16=0 if age16==.
replace age17=0 if age17==.

** Cameroon

replace eth21=0 if eth21==.
replace eth22=0 if eth22==.
replace eth23=0 if eth23==.
replace eth24=0 if eth24==.
replace eth25=0 if eth25==.
replace eth26=0 if eth26==.
replace eth27=0 if eth27==.
replace eth28=0 if eth28==.
replace eth29=0 if eth29==.
replace eth210=0 if eth210==.
replace eth211=0 if eth211==.
replace eth212=0 if eth212==.
replace eth213=0 if eth213==.
replace eth214=0 if eth214==.
replace eth215=0 if eth215==.
replace eth216=0 if eth216==.
replace eth217=0 if eth217==.
replace eth218=0 if eth218==.
replace eth219=0 if eth219==.
replace eth220=0 if eth220==.
replace eth221=0 if eth221==.
replace eth222=0 if eth222==.
replace eth223=0 if eth223==.
replace eth224=0 if eth224==.
replace eth225=0 if eth225==.
replace eth226=0 if eth226==.
replace eth227=0 if eth227==.
replace eth228=0 if eth228==.
replace eth229=0 if eth229==.
replace eth230=0 if eth230==.
replace eth231=0 if eth231==.
replace eth232=0 if eth232==.
replace eth233=0 if eth233==.
replace eth234=0 if eth234==.
replace eth235=0 if eth235==.
replace eth236=0 if eth236==.
replace eth237=0 if eth237==.
replace eth238=0 if eth238==.
replace eth239=0 if eth239==.
replace eth240=0 if eth240==.
replace eth241=0 if eth241==.
replace eth242=0 if eth242==.
replace eth243=0 if eth243==.
replace eth244=0 if eth244==.
replace eth245=0 if eth245==.
replace eth246=0 if eth246==.
replace eth247=0 if eth247==.
replace eth248=0 if eth248==.
replace eth249=0 if eth249==.
replace eth250=0 if eth250==.
replace reg21=0 if reg21==.
replace reg22=0 if reg22==. 
replace reg23=0 if reg23==.
replace reg24=0 if reg24==.
replace reg25=0 if reg25==.
replace reg26=0 if reg26==.
replace reg27=0 if reg27==.
replace reg28=0 if reg28==.
replace reg29=0 if reg29==.
replace reg210=0 if reg210==.
replace reg211=0 if reg211==.
replace reg212=0 if reg212==.
 	
replace age21=0 if age21==.
replace age22=0 if age22==.
replace age23=0 if age23==.
replace age24=0 if age24==.
replace age25=0 if age25==.
replace age26=0 if age26==.
replace age27=0 if age27==.

** Ghana

replace eth31=0 if eth31==.
replace eth32=0 if eth32==.
replace eth33=0 if eth33==.
replace eth34=0 if eth34==.
replace eth35=0 if eth35==.
replace eth36=0 if eth36==.
replace eth37=0 if eth37==.
replace eth38=0 if eth38==.
replace eth39=0 if eth39==.

replace reg31=0 if reg31==.
replace reg32=0 if reg32==. 
replace reg33=0 if reg33==.
replace reg34=0 if reg34==.
replace reg35=0 if reg35==.
replace reg36=0 if reg36==.
replace reg37=0 if reg37==.
replace reg38=0 if reg38==.
replace reg39=0 if reg39==.
replace reg310=0 if reg310==.
 	
replace age31=0 if age31==.
replace age32=0 if age32==.
replace age33=0 if age33==.
replace age34=0 if age34==.
replace age35=0 if age35==.
replace age36=0 if age36==.
replace age37=0 if age37==.

** Kenya

replace eth41=0 if eth41==.
replace eth42=0 if eth42==.
replace eth43=0 if eth43==.
replace eth44=0 if eth44==.
replace eth45=0 if eth45==.
replace eth46=0 if eth46==.
replace eth47=0 if eth47==.
replace eth48=0 if eth48==.
replace eth49=0 if eth49==.
replace eth410=0 if eth410==.
replace eth411=0 if eth411==.
replace eth412=0 if eth412==.
replace eth413=0 if eth413==.
replace eth414=0 if eth414==.
replace eth415=0 if eth415==.

replace reg41=0 if reg41==.
replace reg42=0 if reg42==. 
replace reg43=0 if reg43==.
replace reg44=0 if reg44==.
replace reg45=0 if reg45==.
replace reg46=0 if reg46==.
replace reg47=0 if reg47==.
replace reg48=0 if reg48==.
 	
replace age41=0 if age41==.
replace age42=0 if age42==.
replace age43=0 if age43==.
replace age44=0 if age44==.
replace age45=0 if age45==.
replace age46=0 if age46==.
replace age47=0 if age47==.

** Tanzania

replace reg51=0 if reg51==.
replace reg52=0 if reg52==. 
replace reg53=0 if reg53==.
replace reg54=0 if reg54==.
replace reg55=0 if reg55==.
replace reg56=0 if reg56==.
replace reg57=0 if reg57==.
replace reg58=0 if reg58==.
replace reg59=0 if reg59==.
replace reg510=0 if reg510==.
replace reg511=0 if reg511==.
replace reg512=0 if reg512==.
replace reg513=0 if reg513==.
replace reg514=0 if reg514==.
replace reg515=0 if reg515==.
replace reg516=0 if reg516==.
replace reg517=0 if reg517==.
replace reg518=0 if reg518==.
replace reg519=0 if reg519==.
replace reg520=0 if reg520==.
replace reg521=0 if reg521==.


replace age51=0 if age51==.
replace age52=0 if age52==.
replace age53=0 if age53==.
replace age54=0 if age54==.
replace age55=0 if age55==.
replace age56=0 if age56==.
replace age57=0 if age57==.

** Done!
 
save "all_small_cleaned.dta", replace

drop if missing(hiv)

save "all_small_cleaned_HIVonly.dta", replace


